package com.xuexiang.xuidemo.db;

import ohos.app.Context;
import ohos.data.orm.OrmMigration;

public class XUIDataBaseRepository {
    private volatile static XUIDataBaseRepository sInstance;

    public static final String DATABASE_ALIAS = "XUI";
    public static final String DATABASE_NAME = "XUI.db";

    private OrmMigration mIDatabase;

    private XUIDataBaseRepository() {
    }

    public static XUIDataBaseRepository getInstance() {
        if (sInstance == null) {
            synchronized (XUIDataBaseRepository.class) {
                if (sInstance == null) {
                    sInstance = new XUIDataBaseRepository();
                }
            }
        }
        return sInstance;
    }

    public XUIDataBaseRepository setIDatabase(final OrmMigration iDatabase) {
        mIDatabase = iDatabase;
        return this;
    }

    public DBService getDataBase(final Context context, final Class databaseClazz, final Class tableClass) {
        DBService dbService = new DBService(context, DATABASE_ALIAS, DATABASE_NAME, databaseClazz, mIDatabase);
        return dbService.init(tableClass);
    }
}
